#include <SimpleAmqpClient/SimpleAmqpClient.h>
#include <iostream>
#include <string>
#include <vector>

int main() {
    try {
        // 创建连接
        AmqpClient::Channel::ptr_t channel = AmqpClient::Channel::Create("localhost");
        
        // 声明一个topic类型的exchange
        std::string exchange_name = "topic_logs";
        channel->DeclareExchange(
            exchange_name,                           // exchange名称
            AmqpClient::Channel::EXCHANGE_TYPE_TOPIC, // exchange类型为topic
            false,                                   // durable - 是否持久化
            false,                                   // auto_delete - 是否自动删除
            false                                    // passive - 是否被动声明
        );
        
        // 准备要发布的消息（示例数据）
        std::vector<std::pair<std::string, std::string>> messages = {
            {"quick.orange.rabbit", "First message"},
            {"lazy.orange.elephant", "Second message"},
            {"quick.orange.fox", "Third message"},
            {"orange", "Fourth message"},
            {"quick.orange.rabbit.fast", "Fifth message"},
            {"lazy.brown.fox", "Sixth message"},
            {"shabi.info", "7th message"}
        };
        
        // 发布消息到topic exchange
        for (const auto& msg_pair : messages) {
            std::string routing_key = msg_pair.first;
            std::string message_body = msg_pair.second;
            
            // 创建消息
            AmqpClient::BasicMessage::ptr_t message = AmqpClient::BasicMessage::Create(message_body);
            
            // 发布消息到exchange，使用路由键
            channel->BasicPublish(
                exchange_name,   // exchange - topic exchange名称
                routing_key,     // routing_key - 路由键
                message          // 消息内容
            );
            
            std::cout << " [x] Sent '" << routing_key << "':'" << message_body << "'" << std::endl;
        }
        
        std::cout << "All messages published to topic exchange '" << exchange_name << "'" << std::endl;
        
    } catch (const std::exception& ex) {
        std::cerr << "Error: " << ex.what() << std::endl;
        return 1;
    }
    
    return 0;
}